<?php $this->load->view('templates/backend/header'); ?>
<h3><?php echo $this->lang->line("interested").' '.$this->lang->line("note_customers");?></h3>
<style>
    .fone_num_cls{
        width:15%;  vertical-align: top;
    }
    .navbar-inverse{
        display: none;
    }
    body{
        padding-top:10px;
        padding-bottom:30px;
    }
</style>
<?php if (isset($flash_message)  && $flash_message!=NULL ): ?>
<div class="alert alert-success"><a class="close" customerAssess-dismiss="alert">x</a><strong><?php echo $flash_message; ?></strong></div>
<?php endif; ?>
<div class="well">
    <?php echo form_open();?>
        <div class="tab-content">	
            <div class="tab-pane active" id="main">
                <?php
                echo form_input(array('type'=>'hidden', 'name' => 'customerID', 'id' => 'customerID', 'value' =>$customerAssess->customerID));
                
                echo form_label($this->lang->line('name'), 'name');
                echo form_input(array('disabled'=>'disabled', 'name' => 'name', 'id' => 'name', 'value' => $customerAssess->name));
                echo form_error('name');
                
                  //phone
                echo form_label($this->lang->line('phone'), 'phone');
                foreach($customerAssess->phone as $values){
                    echo form_input(array('disabled'=>'disabled', 'name' => 'phone', 'id' => 'phone', 'value' =>$values,'class'=>'fone_num_cls'));
                }
                echo form_error('phone');
                echo ' ';
                echo form_button(array('id'=>'phone_callback','value' => '3', 'name' => 'callback', 'content' => $this->lang->line('phone_callback'),'class' => 'btn btn-success')).' ';
                echo form_button(array('id'=>'phone_callok','value' => '4', 'name' => 'callok', 'content' => $this->lang->line('phone_callok'),'class' => 'btn btn-success')).' ';
                echo form_input(array('type'=>'hidden', 'name' => 'phone_callstatus', 'id' => 'phone_callstatus', 'value' =>''));
                
                   //Đánh giá tiêu chí của KH
                echo form_label($this->lang->line('interested'), 'interested');
                echo form_dropdown('interested', $this->customerAssess_model->getListInterested(), '');
                echo form_error('interested');
                
                   //ý kiến KH
                echo form_label($this->lang->line('note_customers'), 'note_customers');
                echo form_textarea(array('name' => 'note_customers', 'id' => 'note_customers', 'value' => '','rows'=>'5'));
                echo form_error('note_customers');
                
                    //kiểm tra KH có phải là ng đi mua
                echo form_checkbox(array('name'=>'check_info','id'=>'check_info','value'=>'','checked'=>FALSE,'style'=>'vertical-align: top;')).form_label($this->lang->line('check_info'), 'check_info',array('style'=>'display:inline-block!important;cursor: pointer;'));
                
                echo '<div id="check_info_show">';
                    //SDT KH trực tiếp đi máy bay
                echo form_label($this->lang->line('phone_real'), 'phone_real');
                echo form_input(array('name' => 'phone_real', 'id' => 'phone_real', 'value' => $customerAssess->phone_real,'placeholder'=>$this->lang->line('phone_real')));
                echo form_error('phone_real');
                    //Giá khách mua
                echo form_label($this->lang->line('customer_price'), 'customer_price_fake');
                echo form_input(array('name' => 'customer_price_fake', 'id' => 'customer_price_fake', 'value' => '','placeholder'=>$this->lang->line('customer_price')));
                echo form_input(array('type'=>'hidden', 'name' => 'customer_price', 'id' => 'customer_price', 'value' => ''));
                echo form_error('customer_price_fake');
                echo '</div>';
                ?>
            </div>
        </div>
        <div class="top-button">
                <?php echo form_button(array('id' => 'submit', 'value' => 'Update', 'name' => 'submit', 'type' => 'submit', 'content' => $this->lang->line('save'),'class' => 'btn btn-primary')); ?>
                <?php echo form_button(array('id' => 'cancel','content' => $this->lang->line('close'),'class' => 'btn btn-danger')); ?>
        </div>
    <?php form_close();?>
    <span id="simple-msg-submit"></span>
</div>

<?php $this->load->view('templates/backend/footer'); ?>
<script src="<?php echo base_url().'static/templates/backend/js/autoNumeric.js';?>"></script>

<script>
//var validNavigation = false;
var preventFromExit = true;

$(document).ready(function() {
    $("#check_info_show").hide();
    $("#check_info").on('click',function(){
        var x=$("#check_info").is(":checked");
        if(x){
            $( "#check_info_show" ).fadeIn( "slow", function() {});
        } else {
            $( "#check_info_show" ).fadeOut(1000);
        }
    });
    
    $('#customer_price_fake').autoNumeric('init',{aSign:' VND',mDec:0, pSign:'s' });
    $("#customer_price_fake").blur(function() {
        document.getElementById("customer_price").value = UnFormatNumber($('#customer_price_fake').val());
    });
    
    $('button[type="submit"]').attr('disabled','disabled');
    $( "#phone_callback" ).on('click',function() {
        document.getElementById("phone_callstatus").value           = $(this).val();
        document.getElementById("phone_callback").className         = "btn btn-danger";
        document.getElementById("phone_callok").className           = "btn btn-success";
        $('button[type="submit"]').removeAttr('disabled');
        $('#phone_callok').attr('disabled','disabled');
        
    });
    
    $( "#phone_callok" ).on('click',function() {
        document.getElementById("phone_callstatus").value           = $(this).val();
        document.getElementById("phone_callback").className         = "btn btn-success";
        document.getElementById("phone_callok").className           = "btn btn-danger";
        $('button[type="submit"]').removeAttr('disabled');
        $('#phone_callback').attr('disabled','disabled');
    });

    $("#submit").on('click',function(e){
            setTimeout(function () {
                $.ajax(
                    {
                        url : '/auth/customerAssess/updateInfo/',
                        type: "POST",
                        data : { customerID: $("#customerID").val(), phone_callstatus: $("#phone_callstatus").val(), note_customers: $("#note_customers").val(), phone_real: $("#phone_real").val(), customer_price: $("#customer_price").val()},
                        cache: true,
                        beforeSend: function(){
                            
                        },
                        success:function(data) 
                        {
                            window.top.location.href="/auth/customerAssess/";
                        },
                        error: function() 
                        {
                            alert("Lỗi! Contact Admin!");
                        }
                    });
            }, 222);
            e.preventDefault();	//STOP default action
    });
    
    $("#cancel").on('click',function(e){
            setTimeout(function () {
                $.ajax(
                    {
                        url : '/auth/customerAssess/updateStatus/',
                        type: "POST",
                        data : { customerID: $("#customerID").val(), status: 0},
                        cache: true,
                        beforeSend: function(){
                            
                        },
                        success:function(data) 
                        {
                            if(data == 1){
                                parent.jQuery.fancybox.close();
                            }
                        },
                        error: function() 
                        {
                            alert("Lỗi! Contact Admin!");
                        }
                    });
            }, 222);
            e.preventDefault();	//STOP default action
    });
    wireUpEvents();
});

function UnFormatNumber(x) {
    if (typeof x === "undefined") {
        return '';
    } else {
    return x.toString().replace(/,|VND|\s/g, "");
    }
};
function wireUpEvents() {
    function goodbye(e){        
        $.ajax(
            {
                url : '/auth/customerAssess/updateStatus/',
                type: "POST",
                data : { customerID: $("#customerID").val(), status: 0},
                cache: true,
            });
    }
    window.onbeforeunload=goodbye;
}
</script>